﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//
using DLLTest.OpertionClass;
using Microsoft.Win32;//注册表命名空间

namespace DLLTest
{
    public partial class frm_Register : Form
    {
        //实例化注册表
        SoftReg softreg = new SoftReg();
        //读取ini文件
        iniOperate inioperate = new iniOperate();
        private string strDPath = null;
        private string srcpath = null;       
        //加密解密
        EncDecryOpertion dncdec = new EncDecryOpertion();
        //
        public frm_Register()
        {
            InitializeComponent();
        }

        private void frmRegister_Load(object sender, EventArgs e)
        {
            //txtHD.Text = softreg.GetDiskVolunmeSerialNumber();
            //txtCPU.Text = softreg.getCup();
            //txtHDW.Text = softreg.getMNum();
            //该处需要取得注册码,不加密写入ini文件，为后期判断做依据
            strDPath = Application.StartupPath;
            srcpath = strDPath.Substring(0, strDPath.LastIndexOf("\\")).Substring(0, strDPath.Substring(0, strDPath.LastIndexOf("\\")).LastIndexOf("\\")) + "\\DataBase\\db_DLL.ini";
            //ini读取配置，本次采用读取INI文件信息进行比对，速度快
            //ini路径
            inioperate.IniFile();
            string inifile = inioperate.IniReadValue("软件注册", "注册码");
            if (inifile == "")
            {
                //写入ini文件;
                inioperate.IniWriteValue("软件注册", "注册码", "");
            }
            else
            {
                txtRegcode.Text = inioperate.IniReadValue("软件注册", "注册码"); 
            }
        }     
      
        private void btnexit_Click(object sender, EventArgs e)
        {
           this.Close();
        }

        private void btnGen_Click(object sender, EventArgs e)
        {

            if (txtRegcode.Text == "")
            {
                txtRegcode.Text = softreg.getRNum();
                //写入ini文件;
                inioperate.IniWriteValue("软件注册", "注册码", txtRegcode.Text.Trim());
                MessageBox.Show("请记录文本框中的内容，按照关于内的地址免费注册", "注意");
            }
            else
            {
                MessageBox.Show("请记录文本框中的内容，按照关于内的地址免费注册", "注意");
            }
        }

        private void btnReg_Click_1(object sender, EventArgs e)
        {
            //写入注册表
            //RegistryKey retkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("software", true).CreateSubKey("wxk").CreateSubKey("wxk.INI");
            if (txtRegCoded.Text == "")
            {
                MessageBox.Show("注册码不能为空");
                return;
            }
            else
            {
                //string regcode =dncdec.EncryptStr(txtRegCoded.Text.Trim());
                string regcode = txtRegCoded.Text.Trim();
                //Registry.CurrentUser.SetValue("software\\wxk\\wxk.INI",regcode);
                //写入加密后的值注册表
                Registry.SetValue("HKEY_CURRENT_USER\\SOFTWARE\\wxk\\wxk.INI", "reg", regcode, RegistryValueKind.String);
                //textBox1.Text =(string) Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\wxk\\wxk.INI","reg",0);               
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OperatorsNo opno = new OperatorsNo();
            opno.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            OperatorsNo op = new OperatorsNo();
            op.Show();
        }   
    }
}